/*****************************************************************************
 * cat1.h
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/
#ifndef __CAT1_H__
#define __CAT1_H__

/*****************************************************************************
 * Included Files
 ****************************************************************************/

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Public Types
 ****************************************************************************/
typedef enum {
    DEV_CAT1_EVT_NET_RSSI,
    DEV_CAT1_EVT_NET_CSQ,

    DEV_CAT1_EVT_MQTT_MSG,
    DEV_CAT1_EVT_MQTT_DISCON,
    DEV_CAT1_EVT_MQTT_CONNECT,

} dev_cat1_evt_t;

typedef struct {
    int rssi;
} dev_cat1_net_rssi_t;

typedef struct {
    int csq;
} dev_cat1_net_csq_t;

typedef struct {
    void *         client;
    char *         topic;
    unsigned char *payload;
    unsigned short payloadlen;
} dev_cat1_mqtt_msg_t;

typedef struct {
    char *reserve;
} dev_cat1_mqtt_discon_t;

typedef struct {
    char *reserve;
} dev_cat1_mqtt_connect_t;

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief:  cat1模块初始化
 *
 * @param[]:
 *
 * @return: 返回执行状态
 * **/
int dev_cat1_init(void);

/**
 * @brief:  mqtt初始化
 *
 * @param[in]:  client_id   -   client id
 * @param[in]:  url         -   服务器地址
 * @param[in]:  port        -   服务器端口号
 * @param[in]:  usr         -   用户名
 * @param[in]:  passwd      -   用户密码
 *
 * @return: 返回mqtt句柄
 * **/
void *dev_cat1_mqtt_init(char *client_id, char *url, int port, char *usr,
                         char *passwd);

/**
 * @brief:  订阅
 *
 * @param[in]:  client  -   mqtt句柄
 * @param[in]:  topic   -   待订阅消息
 *
 * @return: 返回执行状态
 * **/
int dev_cat1_mqtt_subscribe(void *client, char *topic);

/**
 * @brief:  注册mqtt消息处理函数
 *
 * @param[in]:  cb      -   回调
 *
 * @return: 返回执行状态
 */
int dev_cat_mqtt_callback_register(void (*cb)(dev_cat1_evt_t evt, void *arg));

/**
 * @brief:  推送消息
 *
 * @param[in]:  client  -
 * @param[in]:  msg     -   消息指针
 *
 * @return: 返回执行状态
 * **/
int dev_cat1_mqtt_publish(void *client, dev_cat1_mqtt_msg_t *msg);

/**
 * @brirf:  查询mqtt消息
 *
 * **/
int dev_cat1_mqtt_loop(void);

/****************************************************************************/
#ifdef __cplusplus
}
#endif
/****************************************************************************/
#endif /* __CAT1_H__ */
/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
